package com.cyl.game.demos.web.service.Impl;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

import javax.annotation.Resource;

import com.cyl.game.demos.web.mapper.FriendshipMapper;
import com.cyl.game.demos.web.entity.Friendship;
import com.cyl.game.demos.web.service.FriendshipService;

@Service
@Transactional
public class FriendshipServiceImpl implements FriendshipService {

    @Resource
    private FriendshipMapper friendshipMapper;

    @Override
    public void addFriendship(Friendship friendship) {
        // 在添加双向好友关系时，需要确保两边关系都正确插入，避免重复插入等问题
        // 可以先检查是否已存在关系，不存在则插入两条记录（正向和反向），这里简化示例先直接插入
        friendshipMapper.insertFriendship(friendship);
    }

    @Override
    public List<Friendship> getFriendshipsByUserId(Integer user_id) {
        return friendshipMapper.selectFriendshipsByUserId(user_id);
    }

    @Override
    public boolean isFriendship(Integer user_id_1, Integer user_id_2) {
        return friendshipMapper.existsFriendshipByIds(user_id_1, user_id_2);
    }

    @Override
    public void deleteFriendship(Integer user_id_1, Integer user_id_2) {
        friendshipMapper.deleteFriendshipByIds(user_id_1, user_id_2);
    }
}